package com.sgb.member.view_model;

import com.sgb.member.di.repository.MemberRepertory;
import com.sgb.member.ui.activity.MemberCompanyWebEditActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.Map;

/**
 * Time:2021/4/30
 * AUTHOR:F_Q
 * Description:
 */
public class MemberCompanyWebEditModel extends BaseViewModel {

    MemberCompanyWebEditActivity activity;
    MemberRepertory repertory;

    public MemberCompanyWebEditModel(MemberCompanyWebEditActivity activity, MemberRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void showOrHideDialog(boolean aBoolean) {
        if (aBoolean) {
            if (!DialogHelper.isShowing()) {
                DialogHelper.showProgressDialog(activity, "数据获取中...");
            }
        } else {
            DialogHelper.dismissProgressDialog();
        }
    }


    public void editCompanyInfo(Map<String, Object> map) {
        showOrHideDialog(true);
        repertory.getApi().updateCompanyInfo(map).enqueue(new ICallBack<BaseEntity<BaseEntity<String>>>() {
            @Override
            public void onSuccess(BaseEntity<BaseEntity<String>> data) {
                activity.editCompanyInfoCallback(map);
            }
        });
    }
}
